﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

using System.IO;

namespace WindowsService1
{
    public partial class RodneyService : ServiceBase
    {

        private Thread worker;
        private int i = 0;

        public RodneyService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            // Set up a timer to trigger every minute.
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 60000; // 60 seconds
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();

        }

        protected override void OnStop()
        {

        }

        public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            StreamWriter sw = new StreamWriter(@"c:\projects\servicetest.txt",true);
            sw.WriteLine(String.Format("Timer expired for the {0} time.", i));
            sw.Close();

            i++;

        }
    }
}
